# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_realname=okular
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=23.08.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('GPL' 'LGPL' 'FDL')
url="https://apps.kde.org/okular/"
pkgdesc="Document Viewer (mingw-w64)"
groups=("${MINGW_PACKAGE_PREFIX}-kde-applications"
        "${MINGW_PACKAGE_PREFIX}-kde-graphics")
depends=("${MINGW_PACKAGE_PREFIX}-discount"
         "${MINGW_PACKAGE_PREFIX}-djvulibre"
         "${MINGW_PACKAGE_PREFIX}-kactivities-qt5${_namesuff}"
         "${MINGW_PACKAGE_PREFIX}-kjs-qt5${_namesuff}"
         "${MINGW_PACKAGE_PREFIX}-kparts-qt5${_namesuff}"
         "${MINGW_PACKAGE_PREFIX}-libkexiv2"
         "${MINGW_PACKAGE_PREFIX}-libspectre"
         "${MINGW_PACKAGE_PREFIX}-phonon-qt5"
         "${MINGW_PACKAGE_PREFIX}-poppler-qt5"
         "${MINGW_PACKAGE_PREFIX}-threadweaver-qt5${_namesuff}")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-chmlib"
             "${MINGW_PACKAGE_PREFIX}-ebook-tools"
             "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
             "${MINGW_PACKAGE_PREFIX}-icoutils"
             "${MINGW_PACKAGE_PREFIX}-kdegraphics-mobipocket"
             "${MINGW_PACKAGE_PREFIX}-kdoctools-qt5${_namesuff}"
             "${MINGW_PACKAGE_PREFIX}-khtml-qt5${_namesuff}"
             "${MINGW_PACKAGE_PREFIX}-ninja")
optdepends=("${MINGW_PACKAGE_PREFIX}-breeze-icons-qt5${_namesuff}: application icon theme"
            "${MINGW_PACKAGE_PREFIX}-chmlib: CHM support"
            "${MINGW_PACKAGE_PREFIX}-ebook-tools: mobi and epub support"
            "${MINGW_PACKAGE_PREFIX}-kdegraphics-mobipocket: mobi support"
            "${MINGW_PACKAGE_PREFIX}-khtml-qt5${_namesuff}: CHM support"
            "${MINGW_PACKAGE_PREFIX}-libzip: CHM support"
            "${MINGW_PACKAGE_PREFIX}-unrar: Comic Book Archive support")
source=(https://download.kde.org/stable/release-service/${pkgver}/src/${_realname}-${pkgver}.tar.xz{,.sig})
sha256sums=('9b46c544f975085298ee7978d552d3078c903a12611a6dbd038fc2b525996838'
            'SKIP')
validpgpkeys=(CA262C6C83DE4D2FB28A332A3A6A4DB839EAA6D7  # Albert Astals Cid <aacid@kde.org>
              F23275E4BF10AFC1DF6914A6DBD2CE893E2D1C87  # Christoph Feck <cfeck@kde.org>
              D81C0CB38EB725EF6691C385BB463350D6EF31EF) # Heiko Becker <heiko.becker@kde.org>

prepare() {
  mkdir -p build-${MSYSTEM}${_variant}
}

build() {
  local -a extra_config
  cd build-${MSYSTEM}${_variant}
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
  fi

  _kde_f5_build_env
  ${MINGW_PREFIX}/bin/cmake.exe ../${_realname}-${pkgver} \
    -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
    "${_kde_f5_KDE_INSTALL_DIRS[@]}" \
    -DBUILD_QCH=OFF \
    -DBUILD_TESTING=OFF \
    -DECM_DIR=${MINGW_PREFIX}/share/ECM \
    -DFORCE_NOT_REQUIRED_DEPENDENCIES=KF5Purpose \
    "${extra_config[@]}" \
    -G'Ninja'
  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${MSYSTEM}${_variant}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./
}
